<?

/** An class to handle features defined for Dataz components
 *  Reads in dzfeatures.ini. This class is used by dzScriptSeppo
 *
 *  This collection of functions (libary) is licensed under GPL2.
 *  See LICENSE or www.gnu.org for more details.
 *
 *  Author Henri Ranki 15.11.2000
 *
 *  $Id: dzfeatures.php 597 2006-04-03 16:15:46Z jyry $
*/

include_once("sodebug.php");
include_once("sostring.php");
include_once("soset.php");
include_once("sogeneric.php");
include_once("soinifiles.php");

/** Data structure that contains the information of the feature
 *  @var soSet $Elements That contains the script elements that makes the feature
 *  @var ? $Event Eventhandler that needs a handler to be assigned
 *  @var ? $EventHandler The name of the event handler. The code for the event handler is
 *      defined in some code element assigned to this feature in $Elements field
 *  @var ? $Stream File where elements are stored
 *  @var soSet $Constants The list of constants copied to head script in the produced html
 */
class dzFeature {
    var $Elements;
    var $Event;
    var $EventHandler;
    var $Stream;
    var $Constants;
} // class dzFeature


/** Set of available features.
 *  Reads in the file defined with DZ_FEATURE_FILE.
 *  @var soSet $Features Henkka, explain this !!!!
 */
class dzFeatureSet extends soBaseClass{
    var $Features;


    /** Constructor
     *  Initialize class. Takes in optional ini file stream -string.
     *  If IniFileName is not specified, then dzfeatures.ini is used.
     *  @param string $IniFileName Alternative Ini file name for dzfeatures.ini.
     */
    function dzFeatureSet($IniFileName = "") {
        $this->Features = new soSet();

        /* no specific ini stream specified? use default then */
        if (!$IniFileName) {
            $IniFileName = dzGetDataxiPath()."/".
                          soExtractVal(basename(__FILE__), ".", -2).".ini";
        }; // if

        $ini_file = dzIniFileCache($IniFileName);

        /* Check that the ini file was found */
        if ($this->Error = $ini_file->Error) {
            dzSysError("Error: Could not find features file: $IniFileName");
        } // if

        $SectionCount = $ini_file->getSectionCount();
        for ($c = $SectionCount -1; $c >= 0; $c--) {
            $NewFeat = new dzFeature();
            $NewFeat->Elements = $ini_file->getValue($c, "elements", NULL);
            $NewFeat->Event = $ini_file->getValue($c, "event", 0);
            $NewFeat->EventHandler =
                $ini_file->getValue($c, "eventhandler", 0);
            $NewFeat->Stream = $ini_file->getValue($c, "scriptstream", 0);
            if (!$NewFeat->Stream) {
                /* default script file */
                $NewFeat->Stream = "dzscript.js";
            }; // if
            $NewFeat->Constants = $ini_file->getValue($c, "constants", NULL);
            $this->Features->addItem($ini_file->getSectionName($c), $NewFeat);
        }; // for
    } // Constructor

    /** Returns a element set.
     *  @param string $Section Section name.
     *  @param string $KeyName Key name.
     *  @param object soIni Ini object to get element set from.
     */
    function getElementSet($Section, $KeyName, &$IniFile) {
        $ElemSet = new soSet();
        $ini_str = trim($IniFile->getValue($Section, $KeyName, 0));
        return $ElemSet->joinArrayAsKeys(soExplode($ini_str, " "));
    } // function getElemetSet(

} // class dzFeatureSet

?>
